const path = require("path");
// const open = require('opn');//打开浏览器
// const chalk = require('chalk');// 改变命令行中输出日志颜色插件
const ip = require('ip').address();
const moduleRules = require('./config/webpack.module.js')
const devServer = require('./config/devServer.js')
const devConfig = require('./config/dev.config.js')
const prodConfig = require('./config/prod.config.js')
console.log(moduleRules('development').module);
const webpackConfig = {
    // 入口文件配置项
    entry: path.resolve(__dirname, "src/main.js"),
    // 输出文件配置项
    output: {
        path: path.resolve(__dirname, 'dist'),
        filename: 'js/[name].[hash].js',
        chunkFilename: 'js/[name].[chunkhash].js',
        publicPath: "/"
    },
    // 模版解析配置项
    resolve: {
        // 设置可省略文件后缀名
        extensions: [' ', '.js', '.json', '.jsx', 'vue'],
        // 查找 module 的话从这里开始查找;
        modules: [path.resolve(__dirname, "src"), path.resolve(__dirname, "node_modules")], // 绝对路径;
        // 配置路径映射（别名）
        alias: {
            '@': path.resolve(__dirname, 'src/'),
            'views': path.resolve(__dirname, 'src/views'),
            '_c': path.resolve(__dirname, 'src/components')
        }
    },
    // 开发工具
    devtool: 'eval-source-map',
    devServer: devServer,
}


module.exports = (env, arge) => {
    console.log('1222', env, arge);
    const config = arge.mode === 'development' ? devConfig : prodConfig
    console.log('config',config);
    return {
        // publicPath: arge.mode === 'development' ? '' : './',
        ...config,
        ...webpackConfig,
        module: moduleRules(arge.mode).module
    }
}

